//
//  XMTabBarController.m
//  Second
//
//  Created by Alex on 16/7/13.
//  Copyright © 2016年 蓝鸥科技有限公司西安分公司. All rights reserved.
//

#import "XMTabBarController.h"

@interface XMTabBarController ()<UITabBarControllerDelegate>

@end

@implementation XMTabBarController


- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    
//    CGAffineTransform rotate = CGAffineTransformMakeRotation( 0 );
//    [UIView animateWithDuration:0.2 animations:^{
//        
//        [[XMTabBer buttonWithTransform].publishButton setTransform:rotate];
//    }];
//        [[XMView standardMenuView] dismiss];
//    [XMTabBer buttonWithTransform].ISShowMenuButton = NO;
    [[XMTabBer buttonWithTransform] buttonTransform];
    
    return YES;
}

+ (void)initialize
{
    //通过appearance统一设置所有UITabBarItem的文字属性
    // 后面带有UI_APPEARANCE_SELECTOR方法，都可以通过appearance对象来统一设置
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    attrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    NSMutableDictionary *seattrs = [NSMutableDictionary dictionary];
    seattrs[NSFontAttributeName] = attrs[NSFontAttributeName];
    seattrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:seattrs forState:UIControlStateSelected];
    
    [[UITabBar appearance]setBarTintColor:[UIColor colorWithRed:169/225.0 green:199/255.0 blue:137/255.0 alpha:1]];

    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.delegate = self;
    
    [self setupChildVC:[[FristViewController alloc]init] title:@"首页" image:@"tabBar_essence_icon" selectedImage:@"tabBar_essence_click_icon"];
    
    [self setupChildVC:[[XMFindController alloc] init] title:@"发现" image:@"tabBar_new_icon" selectedImage:@"tabBar_new_click_icon"];
    
    [self setupChildVC:[[XMCommunityController alloc]init] title:@"社区" image:@"tabBar_friendTrends_icon" selectedImage:@"tabBar_friendTrends_click_icon"];
    
    [self setupChildVC:[[XMMeController alloc]init] title:@"我" image:@"tabBar_me_icon" selectedImage:@"tabBar_me_click_icon"];
    
    [self setValue:[XMTabBer buttonWithTransform] forKeyPath:@"tabBar"];
    
    
    
}

- (void)setupChildVC:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage {
    
    vc.navigationItem.title = title;
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];

   
    
     XMNavigationController *naVC = [[XMNavigationController alloc]initWithRootViewController:vc];
    
    [self addChildViewController:naVC];
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}



@end
